<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 完整菜单配置
    var a = [
        {
            title: "商品管理",
            icon: "el-icon-setting",
            subs: [
                { title: "商品列表", path: "/good" },
                { title: "商品分类", path: "/category" },
                { title: "品牌管理", path: "/brand" },
                { title: "商品属性管理", path: "/attribute" },
            ],
        },
        {
            title: "订单中心",
            icon: "el-icon-setting",
            subs: [{ title: "订单列表", path: "/order" }],
        },
        {
            title: "店铺运营",
            icon: "el-icon-setting",
            subs: [
                { title: "专题管理", path: "/topic" },
                { title: "运营数据", path: "/statdata" },
            ],
        },
    ]

    // 当前用户权限列表
    var b = [
        { id: 3, user_id: 2, path: "/category", path_name: "分类页面" },
        { id: 4, user_id: 2, path: "/good", path_name: "商品页面" },
        { id: 6, user_id: 2, path: "/order", path_name: "订单页面" }
    ]
    // 
    var obj = {
        // '/category': true,
        // "/good": true,
        // "/order": true
    }
    for (let idx = 0; idx < b.length; idx++) {
        let path = b[idx].path
        obj[path] = true
    }
    console.log(obj)
    var c = [];
    // 一级菜单
    for (let i = 0; i < a.length; i++) {
        let subs = [];// 存放新的二级菜单数据
        // 二级菜单
        for (let j = 0; j < a[i].subs.length; j++) {
            let sub = a[i].subs[j];
            // 循环用户权限列表
            // for (let k = 0; k < b.length; k++) {
            //     if (b[k].path === sub.path) {
            //         subs.push(sub)
            //     }
            // }
            // if (obj[sub.path]) {
            //     subs.push(sub)
            // }
            obj[sub.path] && subs.push(sub)
        }
        // console.log(subs)
        if (subs.length > 0) {
            // c.push({
            //     title: a[i].title,
            //     icon: a[i].icon,
            //     subs: subs
            // })
            c.push({ ...a[i], subs })
        }

    }
    console.log(c)
</script>

</html>